home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / mail-tools / thor / thor_2.22 / thor.lha / rexx / CfgSortMail.thor < prev    next >
Text File  |  1995-12-18  |  27KB  |  848 lines

  1. /*
  2. ** $VER: CfgSortMail.thor 2.2a (1.10.95)
  3. ** by Eirik Nicolai Synnes
  4. **
  5. ** Configuration editor for SortMail.thor
  6. **
  7. **
  8. ** Todo:    Check MultiView version?
  9. **
  10. */
  11.  
  12. options results
  13.  
  14. mvopen = 0
  15. system = ""; mailconf = ""; checkcc = 0; stats = 0; delusers = 0
  16. msgactive = 0; mlcount = 0; dgcount = 0
  17.  
  18. /* Open Thor and BBSREAD ARexx ports' */
  19.  
  20. p=address()||' '||show('P',,);if pos('THOR.',p)>0 then thorport=word(substr(p,pos('THOR.',p)),1);else do;say 'No THOR port found!';exit(0);end
  21. if ~show('p', 'BBSREAD') then do; address command; "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"; "WaitForPort BBSREAD"; end
  22.  
  23. address(thorport)
  24.  
  25. /* See if another copy of CfgSortMail is already running */
  26.  
  27. if exists("T:CfgSortMail.tmp") then do
  28.     REQUESTNOTIFY '"Another copy of CfgSortMail\nis probably running."' '"Continue|Abort"'
  29.     if result = 0 then exit(0)
  30.     end
  31.  
  32. call open(tmp, "T:CfgSortMail.tmp", 'W'); call close(tmp)
  33.  
  34. /* Find configuration file and read it*/
  35.  
  36. call open(pn, 'ENV:Thor/THORPATH')
  37. thorpath = readln(pn)
  38. call close(pn)
  39.  
  40. if ~exists(thorpath'rexx') then cfgfile = 'ENV:Thor/SortMail.cfg'
  41. else do
  42.  if exists(thorpath'rexx/SortMail.cfg') then cfgfile = thorpath'rexx/SortMail.cfg'
  43.  else cfgfile = 'ENV:Thor/SortMail.cfg'
  44.  end
  45.  
  46. CURRENTSYSTEM STEM bbs
  47. if rc > 1 then do
  48.     REQUESTNOTIFY '"'THOR.LASTERROR'"' '"_Abort"'
  49.     exit(0)
  50.     end
  51.  
  52. if ~exists(cfgfile) then call cfgsetup(cfgfile)
  53.  
  54. call readcfg
  55.  
  56. /* See if the users reading a message */
  57.  
  58. trace off; CURRENTMSG curmsg; trace on
  59. if rc = 0 then msgactive = 1
  60.  
  61. mainmenu:
  62. /* Display main menu */
  63. menulist.1 = 'Change e-mail conference           'system': 'mailconf
  64. menulist.2 = ''
  65. menulist.3 = 'Configure mailing lists'
  66. menulist.4 = 'Configure digests'
  67. menulist.5 = ''
  68. menulist.6 = 'Parse AmiNet RECENT updates:       '; if aminet ~= 'AMINET' then menulist.6 = menulist.6'YES'; else menulist.6 = menulist.6'NO'
  69. menulist.7 = ' AmiNet RECENT to-address:         '; if aminet ~= 'AMINET' then menulist.7 = menulist.7||aminet; else menulist.7 = menulist.7'NONE'
  70. menulist.8 = ' Delete AmiNet RECENT message      '; if delaminet = 1 then menulist.8 = menulist.8'YES'; else menulist.8 = menulist.8'NO'
  71. menulist.9 = 'UUDecode Amiga Report:             '; if amirep ~= 'AMIREP' then menulist.9 = menulist.9'YES'; else menulist.9 = menulist.9'NO'
  72. menulist.10 = ' Amiga Report from-address:        '; if amirep ~= 'AMIREP' then menulist.10 = menulist.10||amirep; else menulist.10 = menulist.10'NONE'
  73. menulist.11 = 'UUDecode Amiga Link:               '; if amilink ~= 'AMILINK' then menulist.11 = menulist.11'YES'; else menulist.11 = menulist.11'NO'
  74. menulist.12 = ' Amiga Link from-address:          '; if amilink ~= 'AMILINK' then menulist.12 = menulist.12||amilink; else menulist.12 = menulist.12'NONE'
  75. menulist.13 = ''
  76. menulist.14 = 'Enable statistics:                 '; if stats = 1 then menulist.14 = menulist.14'YES'; else menulist.14 = menulist.14'NO'
  77. menulist.15 = 'Check comment fields:              '; if checkcc = 1 then menulist.15 = menulist.15'YES'; else menulist.15 = menulist.15'NO'
  78. menulist.16 = 'Disable user adding:               '; if delusers = 1 then menulist.16 = menulist.16'YES'; else menulist.16 = menulist.16'NO'
  79. menulist.17 = ''
  80. menulist.18 = 'HELP'
  81. menulist.count = 18
  82.  
  83. address(thorport)
  84. REQUESTLIST INSTEM menulist TITLE '"CfgSortMail 2.0 by Eirik Synnes"' SIZEGADGET
  85. if rc ~= 0 then do
  86.     if exists("T:CfgSortMail.tmp") then do
  87.         address(command)
  88.         "Delete T:CfgSortMail.tmp QUIET"
  89.         end
  90.     exit(0)
  91.     end
  92. choice = result
  93.  
  94. /* Check user input */
  95. select
  96.     when choice = menulist.1 then do
  97.         address(bbsread)
  98.         GETBBSLIST STEM bbslist
  99.         address(thorport)
  100.         REQUESTLIST INSTEM bbslist TITLE '"Select system"' SIZEGADGET
  101.         if rc ~= 0 then break
  102.         tempsystem = result
  103.  
  104.         address(bbsread)
  105.         GETCONFLIST BBSNAME '"'tempsystem'"' STEM conflist
  106.         address(thorport)
  107.         REQUESTLIST INSTEM conflist TITLE '"Select conference"' SIZEGADGET
  108.         if rc ~= 0 then break
  109.         mailconf = result
  110.         system = tempsystem
  111.  
  112.         call writecfg(cfgfile)
  113.         end
  114.  
  115.     when choice = menulist.3 then call cfgmaillist(curmsg.msgnr, cfgfile)
  116.     when choice = menulist.4 then call cfgdigest(curmsg.msgnr, cfgfile)
  117.  
  118.     when choice = menulist.6 then do
  119.         if aminet ~= 'AMINET' then do; aminet = 'AMINET'; call writecfg(cfgfile); end
  120.         else do
  121.             address(thorport)
  122.             REQUESTSTRING '"AmiNet RECENT to-address"' ID '"aminet-daily@wunet.wustl.edu"'
  123.             if rc = 0 then do; aminet = result; call writecfg(cfgfile); end
  124.             end
  125.         end
  126.     when choice = menulist.7 then do
  127.         address(thorport)
  128.         REQUESTSTRING '"AmiNet RECENT to-address"' ID '"aminet-daily@wunet.wustl.edu"'
  129.         if rc = 0 then do; aminet = result; call writecfg(cfgfile); end
  130.         end
  131.     when choice = menulist.8 then do
  132.         if delaminet = 0 then delaminet = 1
  133.         else delaminet = 0
  134.         call writecfg(cfgfile)
  135.         end
  136.  
  137.     when choice = menulist.9 then do
  138.         if amirep ~= 'AMIREP' then do; amirep = 'AMIREP'; call writecfg(cfgfile); end
  139.         else do
  140.             address(thorport)
  141.             REQUESTSTRING '"Amiga Report from-address"' ID '"jcompton@xnet.com"'
  142.             if rc = 0 then do; amirep = result; call writecfg(cfgfile); end
  143.             end
  144.         end
  145.  
  146.     when choice = menulist.10 then do
  147.         address(thorport)
  148.         REQUESTSTRING '"Amiga Report from-address"' ID '"jcompton@xnet.com"'
  149.         if rc = 0 then do; amirep = result; call writecfg(cfgfile); end
  150.         end
  151.     when choice = menulist.11 then do
  152.         if amilink ~= 'AMILINK' then do; amilink = 'AMILINK'; call writecfg(cfgfile); end
  153.         else do
  154.             address(thorport)
  155.             REQUESTSTRING '"Amiga Link from-address"' ID '"jcompton@xnet.com"'
  156.             if rc = 0 then do; amilink = result; call writecfg(cfgfile); end
  157.             end
  158.         end
  159.     when choice = menulist.12 then do
  160.         address(thorport)
  161.         REQUESTSTRING '"Amiga Link from-address"' ID '"jcompton@xnet.com"'
  162.         if rc = 0 then do; amilink = result; call writecfg(cfgfile); end
  163.         end
  164.  
  165.     when choice = menulist.14 then do
  166.         if stats = 0 then stats = 1
  167.         else stats = 0
  168.         call writecfg(cfgfile)
  169.         end
  170.     when choice = menulist.15 then do
  171.         if checkcc = 0 then checkcc = 1
  172.         else checkcc = 0
  173.         call writecfg(cfgfile)
  174.         end
  175.     when choice = menulist.16 then do
  176.         if delusers = 0 then delusers = 1
  177.         else delusers = 0
  178.         call writecfg(cfgfile)
  179.         end
  180.  
  181.     when choice = menulist.18 then do
  182.         call help('MAIN')
  183.         end
  184.     otherwise nop
  185.     end
  186.  
  187. signal mainmenu
  188.  
  189. /*
  190. ** Procedures
  191. */
  192.  
  193. help: procedure expose mvopen thorport thorpath
  194.             parse arg node
  195.  
  196. if node = 'MAIN' then page = 1
  197. if node = 'CFGML' then page = 2
  198. if node = 'CFGDG' then page = 3
  199.  
  200. if index(show('P',,), 'MV_SORTMAIL') = 0 then do
  201.     address(thorport)
  202.     GETGLOBALCONFIG STEM GLOBCFG
  203.  
  204.     /* Check version of MultiView? */
  205.     address(command)
  206.     'Run >NIL: MultiView FILE 'thorpath'Docs/SortMail.guide PORTNAME MV_SORTMAIL PUBSCREEN 'GLOBCFG.PUBSCREENNAME
  207.     'WaitForPort MV_SORTMAIL'
  208.     if rc ~= 0 then do
  209.         address(thorport)
  210.         REQUESTNOTIFY '"Couldn''t start MultiView."' '"Sigh"'
  211.         return
  212.         end
  213.     end
  214.  
  215. address(MV_SORTMAIL)
  216. DOTRIGGERMETHOD CONTENTS
  217. do i = 1 to page; DOTRIGGERMETHOD NEXT; end
  218. return
  219.  
  220. cfgmaillist: procedure expose bbs. system mailconf thorport mlcount mlist. dgcount digest. aminet delaminet amirep amilink checkcc stats delusers msgactive thorpath
  221.              parse arg curmsg, cfgfile
  222.  
  223. CDF_NOT_ON_BBS          = '00008000'x  /* This conference is not on the bbs. */
  224.  
  225. mlistmenu:
  226.  
  227. menulist.1 = 'Add new mailing list'
  228. menulist.2 = 'Edit mailing list'
  229. menulist.3 = 'Delete mailing list'
  230. menulist.count = 3
  231.  
  232. address(thorport)
  233. REQUESTLIST INSTEM menulist TITLE '"Configure mailing lists"' SIZEGADGET
  234. if rc ~= 0 then return
  235. choice = result
  236.  
  237. if choice = menulist.1 then signal addmlist
  238. if choice = menulist.2 then signal editmlist
  239. if choice = menulist.3 then signal delmlist
  240. signal mlistmenu
  241.  
  242.  
  243. addmlist:
  244. REQUESTSTRING TITLE '"Enter a conference name"' BT '"_Ok|_Cancel"' ID '"(ML) "' MAXCHARS 80
  245. if rc ~= 0 then signal mlistmenu
  246. toconf = result
  247. toconf = strip(toconf)
  248.  
  249. mlcount = mlcount + 1
  250. mlist.mlcount.name = toconf
  251. toconfnr = mlcount
  252. mlist.toconfnr.addrcount = 0
  253. mlist.toconfnr.namecount = 0
  254.  
  255. edit = 0
  256.  
  257. signal editmlistdata
  258.  
  259. editmlist:
  260. if mlcount > 0 then do
  261.     do n = 1 to mlcount; conflist.n = mlist.n.name; end
  262.     conflist.count = mlcount
  263.     REQUESTLIST INSTEM conflist TITLE '"Select a mailing list"' SIZEGADGET
  264.     if rc ~= 0 then signal mlistmenu
  265.     toconf = result
  266.     do n = 1 to mlcount; if toconf = mlist.n.name then toconfnr = n; end
  267.     end
  268. else do
  269.     REQUESTNOTIFY '"There are no configured mailing lists."' '"_Abort"'
  270.     signal mlistmenu
  271.     end
  272.  
  273. edit = 1
  274.  
  275. editmlistdata:
  276. if msgactive = 1 & bbs.CONFNAME = mailconf then do
  277.     address(bbsread)
  278.     READBRMESSAGE '"'system'"' '"'mailconf'"' curmsg HEADSTEM head TEXTSTEM text
  279.     if rc ~= 0 then do
  280.         address(thorport)
  281.         REQUESTNOTIFY '"Couldn''t get info on active message:\n'BBSREAD.LASTERROR'"' '"_Abort"'
  282.         return
  283.         end
  284.     address(thorport)
  285.     end
  286.  
  287. if mlist.toconfnr.replyaddr = 'MLIST.'toconfnr'.REPLYADDR' then do
  288.     if text.REPLYADDR ~= 'TEXT.REPLYADDR' then mlist.toconfnr.replyaddr = text.REPLYADDR
  289.     else if head.TOADDR ~= 'HEAD.TOADDR' then mlist.toconfnr.replyaddr = head.TOADDR
  290.     end
  291.  
  292. editmlistmenu:
  293. menulist.1 = 'Add to-address'; addaddr = 1; n = 2
  294. do i = 1 to mlist.toconfnr.addrcount
  295.     menulist.n = ' 'mlist.toconfnr.toaddr.i
  296.     n = n + 1
  297.     end
  298.  
  299. menulist.n = 'Add to-name'; addname = n; n = n + 1
  300. do i = 1 to mlist.toconfnr.namecount
  301.     menulist.n = ' 'mlist.toconfnr.toname.i
  302.     n = n + 1
  303.     end
  304.  
  305. if mlist.toconfnr.fromf = 'MLIST.'toconfnr'.FROMF' | mlist.toconfnr.fromf = '' then menulist.n = 'From field: NONE'
  306. else menulist.n = 'From field: 'mlist.toconfnr.fromf
  307. fromfield = n; n = n + 1
  308.  
  309. if mlist.toconfnr.replyaddr = 'MLIST.'toconfnr'.REPLYADDR' then menulist.n = 'Reply address: EDIT ME'
  310. else menulist.n = 'Reply address: 'mlist.toconfnr.replyaddr
  311. repaddr = n; n = n + 1
  312.  
  313. menulist.n = ''; n = n + 1
  314. menulist.n = 'HELP'
  315.  
  316. menulist.count = n
  317.  
  318. REQUESTLIST INSTEM menulist TITLE '"'toconf'"' SIZEGADGET
  319. if rc ~= 0 then do
  320.     if mlist.toconfnr.replyaddr = 'MLIST.'toconfnr'.REPLYADDR' then do
  321.         REQUESTNOTIFY '"You should edit the reply address before exiting.\nAre you sure you want to exit?"' '"Yes|No"'
  322.         if result = 0 then signal editmlistmenu
  323.         end
  324.     call writecfg(cfgfile)
  325.     signal mlistmenu
  326.     end
  327. choice = result
  328.  
  329. select
  330.     when choice = menulist.addaddr then do
  331.         mlist.toconfnr.addrcount = mlist.toconfnr.addrcount + 1
  332.         addrs = mlist.toconfnr.addrcount
  333.         if head.TOADDR ~= 'HEAD.TOADDR' then do
  334.             mlist.toconfnr.toaddr.addrs = head.TOADDR
  335.             addrid = mlist.toconfnr.toaddr.addrs
  336.             end
  337.         else addrid = ''
  338.         REQUESTSTRING TITLE '"Enter a to-address"' BT '"_Ok|_Cancel"' ID '"'addrid'"' MAXCHARS 40
  339.         if rc ~= 0 then do
  340.             mlist.toconfnr.addrcount = mlist.toconfnr.addrcount - 1
  341.             signal editmlistmenu
  342.             end
  343.         mlist.toconfnr.toaddr.addrs = result
  344.         call writecfg(cfgfile)
  345.         end
  346.  
  347.     when choice = menulist.addname then do
  348.         mlist.toconfnr.namecount = mlist.toconfnr.namecount + 1
  349.         names = mlist.toconfnr.namecount
  350.         if head.TONAME ~= 'HEAD.TONAME' then do
  351.             mlist.toconfnr.toname.names = head.TOname
  352.             nameid = mlist.toconfnr.toname.names
  353.             end
  354.         else nameid = ''
  355.         REQUESTSTRING TITLE '"Enter a to-name"' BT '"_Ok|_Cancel"' ID '"'nameid'"' MAXCHARS 40
  356.         if rc ~= 0 then do
  357.             mlist.toconfnr.namecount = mlist.toconfnr.namecount - 1
  358.             signal editmlistmenu
  359.             end
  360.         mlist.toconfnr.toname.names = result
  361.         call writecfg(cfgfile)
  362.         end
  363.  
  364.     when choice = menulist.repaddr then do
  365.         if mlist.toconfnr.replyaddr = 'mlist.toconfnr.replyaddr' then repid = ""
  366.         else repid = mlist.toconfnr.replyaddr
  367.         REQUESTSTRING TITLE '"Enter a reply-address"' BT '"_Ok|_Cancel"' ID '"'repid'"' MAXCHARS 40
  368.         if rc ~= 0 then signal editmlistmenu
  369.         mlist.toconfnr.replyaddr = result
  370.         call writecfg(cfgfile)
  371.         end
  372.  
  373.     when choice = menulist.fromfield then do
  374.         fromfid = 'NONE'
  375.         if msgactive = 1 & text.COMMENT.COUNT ~= 'TEXT.COMMENT.COUNT' & text.COMMENT.COUNT > 0 then do i = 1 to text.COMMENT.COUNT
  376.             if upper(left(text.COMMENT.i, 4)) = "FROM" then do
  377.                 fromfid = subword(text.COMMENT.i, 2)
  378.                 end
  379.             end
  380.  
  381.         fromfid = translate(fromfid, '<>', '()')
  382.         i = pos("<", from)
  383.         if i ~= 0 then do
  384.             checkaddr = strip(substr(fromfid, i, pos('>', fromfid) - i), B, ' <>"')
  385.             if pos("@", checkaddr) > 0 then do
  386.                 fromfid = checkaddr
  387.                 end
  388.             end
  389.         else fromfid = subword(strip(fromfid, B, ' "'), 1, 1)
  390.  
  391.         REQUESTSTRING TITLE '"NONE to disable"' BT '"_Ok|_Cancel"' ID '"'fromfid'"' MAXCHARS 40
  392.         if rc ~= 0 then signal editmlistmenu
  393.         if result ~= 'NONE' then mlist.toconfnr.fromf = result
  394.         else drop mlist.toconfnr.fromf
  395.         call writecfg(cfgfile)
  396.         end
  397.  
  398.     when choice = 'HELP' then do
  399.         call help('CFGML')
  400.         end
  401.  
  402.     otherwise do
  403.         do i = 1 to mlist.toconfnr.addrcount
  404.             if choice = mlist.toconfnr.toaddr.i then do
  405.                 REQUESTNOTIFY '"Do you want to edit\nor delete this item?"' '"Edit|Delete"'
  406.                 if result = 0 then do
  407.                     REQUESTNOTIFY '"Sure you want to remove\n'choice'\nas a search criteria?"' '"_Yes|_No"'
  408.                     if result = 1 then do
  409.                         k = 1
  410.                         do j = 1 to mlist.toconfnr.addrcount
  411.                             if mlist.toconfnr.toaddr.j ~= choice then do
  412.                                 mlist.toconfnr.toaddr.k = mlist.toconfnr.toaddr.j
  413.                                 k = k + 1
  414.                                 end
  415.                             end
  416.                         mlist.toconfnr.addrcount = mlist.toconfnr.addrcount - 1
  417.                         call writecfg(cfgfile)
  418.                         end
  419.                     end
  420.                 else do
  421.                     REQUESTSTRING TITLE '"Edit to-address"' BT '"_Ok|_Cancel"' ID '"'mlist.toconfnr.toaddr.i'"' MAXCHARS 40
  422.                     if rc = 0 then do
  423.                         mlist.toconfnr.toaddr.i = result
  424.                         call writecfg(cfgfile)
  425.                         end
  426.                     end
  427.                 end
  428.             end
  429.         do i = 1 to mlist.toconfnr.namecount
  430.             if choice = mlist.toconfnr.toname.i then do
  431.                 REQUESTNOTIFY '"Do you want to edit\nor delete this item?"' '"Edit|Delete"'
  432.                 if result = 0 then do
  433.                     REQUESTNOTIFY '"Do you want to remove\n'choice'\nas a search criteria?"' '"_Yes|_No"'
  434.                     if result = 1 then do
  435.                         k = 1
  436.                         do j = 1 to mlist.toconfnr.namecount
  437.                             if mlist.toconfnr.toname.j ~= choice then do
  438.                                 mlist.toconfnr.toname.k = mlist.toconfnr.toname.j
  439.                                 k = k + 1
  440.                                 end
  441.                             end
  442.                         mlist.toconfnr.namecount = mlist.toconfnr.namecount - 1
  443.                         call writecfg(cfgfile)
  444.                         end
  445.                 else do
  446.                     REQUESTSTRING TITLE '"Edit to-name"' BT '"_Ok|_Cancel"' ID '"'mlist.toconfnr.toname.i'"' MAXCHARS 40
  447.                     if rc = 0 then do
  448.                         mlist.toconfnr.toname.i = result
  449.                         call writecfg(cfgfile)
  450.                         end
  451.                     end
  452.                 end
  453.             end
  454.         end
  455.     end
  456. end
  457.  
  458. signal editmlistmenu
  459.  
  460. delmlist:
  461.  
  462. if mlcount > 0 then do
  463.     do n = 1 to mlcount; conflist.n = mlist.n.name; end
  464.     conflist.count = mlcount
  465.     REQUESTLIST INSTEM conflist TITLE '"Select a mailling list"' SIZEGADGET 
  466.     if rc ~= 0 then signal mlistmenu
  467.     delconf = result
  468.     REQUESTNOTIFY '"Do you want to remove this entry from\nSortMail''s configuration? (I will only\nstop sorting it, not delete the conference)"' "Yes|_No"
  469.     if result = 0 then signal mlistmenu
  470.     counter = 1
  471.     do n = 1 to mlcount
  472.         if mlist.n.name = delconf then n = n + 1
  473.         mlist.counter.name = mlist.n.name
  474.         if addrcount > 0 then do m = 1 to mlist.counter.addrcount
  475.             mlist.counter.toaddr.m = mlist.n.toaddr.m
  476.             end
  477.         if namecount > 0 then do m = 1 to mlist.counter.namecount
  478.             mlist.counter.toname.m = mlist.n.toname.m
  479.             end
  480.         mlist.counter.replyaddr = mlist.n.replyaddr
  481.         counter = counter + 1
  482.         if counter > mlcount then leave
  483.         end
  484.     mlcount = mlcount - 1
  485.     call writecfg(cfgfile)
  486.     end
  487. else do
  488.     REQUESTNOTIFY '"There are no configured mailing lists."' '"_Abort"'
  489.     end
  490. signal mlistmenu
  491.  
  492.  
  493. readcfg: procedure expose cfgfile system mailconf aminet delaminet amirep amilink checkcc mlist. digest. mlcount dgcount stats delusers thorpath
  494.  
  495. /* Open and read configuration file */
  496. call open(cf, cfgfile, 'R')
  497. do until eof(cf)
  498.     subentry = ""
  499.     entry = readln(cf)
  500.     select
  501.         when upper(entry) = "SYSTEM" then do until upper(subentry) = "END"
  502.             subentry = readln(cf)
  503.             select
  504.                 when upper(subword(subentry, 1, 1)) = 'BBS:' then system = subword(subentry, 2)
  505.                 when upper(subword(subentry, 1, 1)) = 'CONF:' then mailconf = subword(subentry, 2)
  506.                 when upper(subword(subentry, 1, 1)) = 'AMINET:' then aminet = subword(subentry, 2)
  507.                 when upper(subword(subentry, 1, 1)) = 'DELAMINET:' then if upper(subword(subentry, 2, 1)) = 'YES' then delaminet = 1
  508.                 when upper(subword(subentry, 1, 1)) = 'AMIREP:' then amirep = subword(subentry, 2)
  509.                 when upper(subword(subentry, 1, 1)) = 'AMILINK:' then amilink = subword(subentry, 2)
  510.                 when upper(subword(subentry, 1, 1)) = 'CHECKCC:' then if upper(subword(subentry, 2, 1)) = 'YES' then checkcc = 1
  511.                 when upper(subword(subentry, 1, 1)) = 'STATISTICS:' then if upper(subword(subentry, 2, 1)) = 'YES' then stats = 1
  512.                 when upper(subword(subentry, 1, 1)) = 'DELUSERS:' then if upper(subword(subentry, 2, 1)) = 'YES' then delusers = 1
  513.                 otherwise nop
  514.                 end
  515.             end
  516.  
  517.         when upper(entry) = "MAILLIST" then do
  518.             mlcount = mlcount + 1
  519.             addrs = 0; names = 0
  520.             do until upper(subentry) = "END"
  521.                 subentry = readln(cf)
  522.                 select
  523.                     when upper(subword(subentry, 1, 1)) = 'LISTNAME:' then mlist.mlcount.name = subword(subentry, 2)
  524.                     when upper(subword(subentry, 1, 1)) = 'TOADDR:' then do
  525.                         addrs = addrs + 1
  526.                         mlist.mlcount.toaddr.addrs = subword(subentry, 2)
  527.                         end
  528.                     when upper(subword(subentry, 1, 1)) = 'TONAME:' then do
  529.                         names = names + 1
  530.                         mlist.mlcount.toname.names = subword(subentry, 2)
  531.                         end
  532.                     when upper(subword(subentry, 1, 1)) = 'FROMFIELD:' then mlist.mlcount.fromf = subword(subentry, 2)
  533.                     when upper(subword(subentry, 1, 1)) = 'REPLYADDR:' then mlist.mlcount.replyaddr = subword(subentry, 2)
  534.                     otherwise nop
  535.                     end
  536.                 mlist.mlcount.addrcount = addrs
  537.                 mlist.mlcount.namecount = names
  538.                 mlist.mlcount.fromfcount = fromfs
  539.                 end
  540.             end
  541.  
  542.         when upper(entry) = "DIGEST" then do
  543.             dgcount = dgcount + 1
  544.             addrs = 0; names = 0
  545.             digest.dgcount.deldigest = 0
  546.             do until upper(subentry) = "END"
  547.                 subentry = readln(cf)
  548.                 select
  549.                     when upper(subword(subentry, 1, 1)) = 'DIGESTNAME:' then digest.dgcount.name = subword(subentry, 2)
  550.                     when upper(subword(subentry, 1, 1)) = 'TOADDR:' then do
  551.                         addrs = addrs + 1
  552.                         digest.dgcount.toaddr.addrs = subword(subentry, 2)
  553.                         end
  554.                  when upper(subword(subentry, 1, 1)) = 'TONAME:' then do
  555.                         names = names + 1
  556.                         digest.dgcount.toname.names = subword(subentry, 2)
  557.                         end
  558.                  when upper(subword(subentry, 1, 1)) = 'REPLYADDR:' then digest.dgcount.replyaddr = subword(subentry, 2)
  559.                  when upper(subword(subentry, 1, 1)) = 'ENDSUBMSG:' then digest.dgcount.endsubmsg = subword(subentry, 2)
  560.                  when upper(subword(subentry, 1, 1)) = 'ENDDIGEST:' then digest.dgcount.enddigest = subword(subentry, 2)
  561.                  when upper(subword(subentry, 1, 1)) = 'DELDIGEST:' then if upper(subword(subentry, 2, 1)) = 'YES' then digest.dgcount.deldigest = 1
  562.                  otherwise nop
  563.                  end
  564.              digest.dgcount.addrcount = addrs
  565.              digest.dgcount.namecount = names
  566.              end
  567.          end
  568.         otherwise nop
  569.         end
  570.     end
  571. call close(cf)
  572. return
  573.  
  574.  
  575. writecfg: procedure expose bbs. system mailconf aminet delaminet amirep amilink mlcount mlist. dgcount digest. checkcc stats delusers thorpath
  576.           parse arg cfgfile
  577.  
  578. call open(cf, cfgfile, 'W')
  579. call writeln(cf, 'SYSTEM')
  580. call writeln(cf, 'BBS: '||system)
  581. call writeln(cf, 'Conf: '||mailconf)
  582. if aminet ~= "AMINET" then call writeln(cf, 'AmiNet: '||aminet)
  583. if delaminet = 1 then call writeln(cf, 'DelAmiNet: YES')
  584. else call writeln(cf, 'DelAmiNet: NO')
  585. if amirep ~= "AMIREP" then call writeln(cf, 'AmiRep: '||amirep)
  586. if amilink ~= "AMILINK" then call writeln(cf, 'AmiLink: '||amilink)
  587. if checkcc = 1 then call writeln(cf, 'CheckCC: YES')
  588. else call writeln(cf, 'CheckCC: NO')
  589. if stats = 1 then call writeln(cf, 'Statistics: YES')
  590. else call writeln(cf, 'Statistics: NO')
  591. if delusers = 1 then call writeln(cf, 'DelUsers: YES')
  592. else call writeln(cf, 'DelUsers: NO')
  593. call writeln(cf, 'END')
  594. call writeln(cf, '')
  595.  
  596. if mlcount > 0 then do n = 1 to mlcount
  597.     call writeln(cf, 'MAILLIST')
  598.     call writeln(cf, 'ListName: 'mlist.n.name)
  599.     if mlist.n.addrcount > 0 then do m = 1 to mlist.n.addrcount
  600.         call writeln(cf, 'ToAddr: 'mlist.n.toaddr.m)
  601.         end
  602.     if mlist.n.namecount > 0 then do m = 1 to mlist.n.namecount
  603.         call writeln(cf, 'ToName: 'mlist.n.toname.m)
  604.         end
  605.     if mlist.n.fromf ~= 'MLIST.'n'.FROMF' then call writeln(cf, 'FromField: 'mlist.n.fromf)
  606.     call writeln(cf, 'ReplyAddr: 'mlist.n.replyaddr)
  607.     call writeln(cf, 'END')
  608.     call writeln(cf, '')
  609.     end
  610.  
  611. if dgcount > 0 then do n = 1 to dgcount
  612.     call writeln(cf, 'DIGEST')
  613.     call writeln(cf, 'DigestName: 'digest.n.name)
  614.     if digest.n.addrcount > 0 then do m = 1 to digest.n.addrcount
  615.         call writeln(cf, 'ToAddr: 'digest.n.toaddr.m)
  616.         end
  617.     if digest.n.namecount > 0 then do m = 1 to digest.n.namecount
  618.         call writeln(cf, 'ToName: 'digest.n.toname.m)
  619.         end
  620.     call writeln(cf, 'ReplyAddr: 'digest.n.replyaddr)
  621.     call writeln(cf, 'EndSubMsg: 'digest.n.endsubmsg)
  622.     if digest.n.enddigest ~= 'DIGEST.'n'.ENDDIGEST' then call writeln(cf, 'EndDigest: 'digest.n.enddigest)
  623.     if digest.n.deldigest = 1 then call writeln(cf, 'DelDigest: YES')
  624.     else call writeln(cf, 'DelDigest: NO')
  625.     call writeln(cf, 'END')
  626.     call writeln(cf, '')
  627.     end
  628. call close(cf)
  629.  
  630. if cfgfile = 'ENV:Thor/SortMail.cfg' then do
  631.     address(command)
  632.     'Copy "'cfgfile'" "ENVARC:Thor/SortMail.cfg" QUIET'
  633.     end
  634.  
  635. return
  636.  
  637.  
  638. cfgsetup: procedure expose thorport bbs. aminet delaminet amirep amilink checkcc mlcount mlist. dgcount digest. stats delusers
  639.           parse arg cfgfile
  640.  
  641. if bbs.CONFNAME = "" then do
  642.     address(thorport)
  643.     REQUESTNOTIFY '"Please enter your Internet E-Mail\nconference before running this script."' '"Ok"'
  644.     if exists("T:CfgSortMail.tmp") then do
  645.         address(command)
  646.         "Delete T:CfgSortMail.tmp QUIET"
  647.         end
  648.     exit(0)
  649.     end
  650.  
  651. address(thorport)
  652. REQUESTNOTIFY '"Is the current conference\n('bbs.BBSNAME': 'bbs.CONFNAME')\nyour Internet E-Mail conference?"' '"Yes|No"'
  653. if result = 0 then do
  654.     if exists("T:CfgSortMail.tmp") then do
  655.         address(command)
  656.         "Delete T:CfgSortMail.tmp QUIET"
  657.         end
  658.     exit(0)
  659.     end
  660.  
  661. system = bbs.BBSNAME
  662. mailconf = bbs.CONFNAME
  663.  
  664. call writecfg(cfgfile)
  665. return
  666.  
  667.  
  668. cfgdigest: procedure expose bbs. system mailconf thorport mlcount mlist. dgcount digest. aminet delaminet amirep amilink checkcc stats delusers thorpath
  669.            parse arg curmsg, cfgfile
  670.  
  671. CDF_NOT_ON_BBS          = '00008000'x  /* This conference is not on the bbs. */
  672.  
  673. if curmsg = 'CURMSG.MSGNR' then do
  674.     address(thorport)
  675.     REQUESTNOTIFY '"Digest configuration requires\nan active message."' '"I see"'
  676.     return
  677.     end
  678.  
  679. address(bbsread)
  680. READBRMESSAGE '"'system'"' '"'mailconf'"' curmsg HEADSTEM head TEXTSTEM text
  681. if rc ~= 0 then do
  682.     address(thorport)
  683.     REQUESTNOTIFY '"'BBSREAD.LASTERROR'\nMake sure you have a\ndigest message active\nin the main window."' '"_Abort"'
  684.     return
  685.     end
  686.  
  687. digestmenu:
  688.  
  689. menulist.1 = 'Add new digest'
  690. menulist.2 = 'Edit digest'
  691. menulist.3 = 'Delete digest'
  692. menulist.4 = ''
  693. menulist.5 = 'HELP'
  694. menulist.count = 5
  695.  
  696. address(thorport)
  697. REQUESTLIST INSTEM menulist TITLE '"Configure digests"' SIZEGADGET
  698. if rc ~= 0 then return
  699. choice = result
  700.  
  701. if choice = menulist.1 then signal adddigest
  702. if choice = menulist.2 then signal editdigest
  703. if choice = menulist.3 then signal deldigest
  704. if choice = menulist.5 then call help('CFGDG')
  705.  
  706. signal digestmenu
  707.  
  708. adddigest:
  709. REQUESTSTRING TITLE '"Enter a conference name"' BT '"_Ok|_Cancel"' ID '"(DG) "' MAXCHARS 80
  710. if rc ~= 0 then signal digestmenu
  711. toconf = result
  712. toconf = strip(toconf)
  713.  
  714. do n = 1 to dgcount
  715.     if digest.n.name = toconf then do
  716.         REQUESTNOTIFY '"A conference named '''toconf''' is already used\nfor digests. Please choose another name."' '"Ok"'
  717.         signal adddigest
  718.         end
  719.     end
  720.  
  721. dgcount = dgcount + 1
  722. digest.dgcount.name = toconf
  723. toconfnr = dgcount
  724. digest.toconfnr.addrcount = 0
  725. digest.toconfnr.namecount = 0
  726.  
  727. digest.toconfnr.addrcount = digest.toconfnr.addrcount + 1
  728. addrs = digest.toconfnr.addrcount
  729. digest.toconfnr.toaddr.addrs = head.TOADDR
  730. digest.toconfnr.replyaddr = text.REPLYADDR
  731.  
  732. edit = 0
  733.  
  734. signal editdigestdata
  735.  
  736. editdigest:
  737. if dgcount > 0 then do
  738.     do n = 1 to dgcount; conflist.n = digest.n.name; end
  739.     conflist.count = dgcount
  740.     REQUESTLIST INSTEM conflist TITLE '"Select a digest"' SIZEGADGET 
  741.     if rc ~= 0 then signal digestmenu
  742.     toconf = result
  743.     do n = 1 to dgcount; if toconf = digest.n.name then toconfnr = n; end
  744.     end
  745. else do
  746.     REQUESTNOTIFY '"There are no configured digests."' '"_Abort"'
  747.     signal digestmenu
  748.     end
  749.  
  750. edit = 1
  751.  
  752. editdigestdata:
  753. if digest.toconfnr.replyaddr = 'TEXT.REPLYADDR' then replyid = head.FROMADDR
  754. else replyid = digest.toconfnr.replyaddr
  755. REQUESTSTRING TITLE '"Enter a reply-address"' BT '"_Ok|_Cancel"' ID '"'replyid'"' MAXCHARS 40
  756. if rc ~= 0 then do
  757.     if edit = 0 then dgcount = dgcount - 1
  758.     signal digestmenu
  759.     end
  760.  
  761. digest.toconfnr.replyaddr = result
  762.  
  763. do n = 1 to text.TEXT.COUNT
  764.     if upper(left(text.text.n, 6)) = 'FROM: ' then break
  765.     end
  766. do n = n+1 to text.TEXT.COUNT
  767.     if upper(left(text.text.n, 6)) = 'FROM: ' then break
  768.     end
  769. n = n + 5
  770.  
  771. m = 1
  772. do o = n-30 to n
  773.     if left(text.text.o, 10) ~= 'TEXT.TEXT.' then do
  774.         endmsg.m = text.TEXT.o
  775.         m = m + 1
  776.         end
  777.     end
  778. endmsg.count = n
  779.  
  780. if edit = 1 then do
  781.     REQUESTNOTIFY '"Do you want to edit the ''end of message''\nline?  If yes, the 20 last lines from the\ncurrent message will be shown in a listview."' '"Yes|_No"'
  782.     editeom = result
  783.     end
  784. else editeom = 1
  785.  
  786. if editeom = 1 then do
  787.     REQUESTLIST INSTEM endmsg TITLE '"Select ''end of message'' line"' SIZEGADGET 
  788.     if rc ~= 0 then do
  789.         if edit ~= 1 then dgcount = dgcount - 1
  790.         signal digestmenu
  791.         end
  792.     digest.toconfnr.endsubmsg = result
  793.     end
  794.  
  795. REQUESTNOTIFY '"Do you want parsed digests to be deleted?\nWarning: Do NOT enable this until you are\ncertain the digests are parsed properly!"' '"Yes|_No|_Abort"'
  796. digest.toconfnr.deldigest = result
  797. if digest.toconfnr.deldigest = 0 then do
  798.     if edit ~= 1 then dgcount = dgcount - 1
  799.     signal digestmenu
  800.     end
  801. if digest.toconfnr.deldigest = 2 then digest.toconfnr.deldigest = 0
  802.  
  803. address(bbsread)
  804. CONFIGCONF '"'system'"' '"'toconf'"' SET c2x(CDF_NOT_ON_BBS)
  805. if rc ~= 0 then do
  806.     address(thorport)
  807.     REQUESTNOTIFY '"'BBSREAD.LASTERROR'"' '"_Abort"'
  808.     end
  809.  
  810. call writecfg(cfgfile)
  811. signal digestmenu
  812.  
  813.  
  814. deldigest:
  815.  
  816. if dgcount > 0 then do
  817.     do n = 1 to dgcount; conflist.n = digest.n.name; end
  818.     conflist.count = dgcount
  819.     REQUESTLIST INSTEM conflist TITLE '"Select a digest"' SIZEGADGET 
  820.     if rc ~= 0 then signal digestmenu
  821.     delconf = result
  822.     REQUESTNOTIFY '"Do you want to remove this entry from\nSortMail''s configuration? (I will only\nstop parsing, not delete the conference)"' "Yes|_No"
  823.     if result = 0 then signal digestmenu
  824.     counter = 1
  825.     do n = 1 to dgcount
  826.         if digest.n.name = delconf then n = n + 1
  827.             digest.counter.name = digest.n.name
  828.             if addrcount > 0 then do m = 1 to digest.counter.addrcount
  829.                 digest.counter.toaddr.m = digest.n.toaddr.m
  830.             end
  831.         if namecount > 0 then do m = 1 to digest.counter.namecount
  832.             digest.counter.toname.m = digest.n.toname.m
  833.             end
  834.         digest.counter.replyaddr = digest.n.replyaddr
  835.         digest.counter.endsubmsg = digest.n.endsubmsg
  836.         digest.counter.enddigest = digest.n.enddigest
  837.         digest.counter.deldigest = digest.n.deldigest
  838.         counter = counter + 1
  839.         if counter > dgcount then leave
  840.         end
  841.     dgcount = dgcount - 1
  842.     call writecfg(cfgfile)
  843.     end
  844. else do
  845.     REQUESTNOTIFY '"There are no configured digests."' '"_Abort"'
  846.     end
  847. signal digestmenu
  848.